export const agentImageURL = url => {
  return url.replace(/(https|http):\/\//, '//images.weserv.nl/?url=');
};

export const formatDate = date => {
  return new Date(parseInt(date) * 1000).Format('yyyy-MM-dd hh:mm');
};
Date.prototype.Format = function(fmt) {
  //author: meizz
  var o = {
    'M+': this.getMonth() + 1, //月份
    'd+': this.getDate(), //日
    'h+': this.getHours(), //小时
    'm+': this.getMinutes(), //分
    's+': this.getSeconds(), //秒
    'q+': Math.floor((this.getMonth() + 3) / 3), //季度
    S: this.getMilliseconds() //毫秒
  };
  if (/(y+)/.test(fmt))
    fmt = fmt.replace(
      RegExp.$1,
      (this.getFullYear() + '').substr(4 - RegExp.$1.length)
    );
  for (var k in o)
    if (new RegExp('(' + k + ')').test(fmt))
      fmt = fmt.replace(
        RegExp.$1,
        RegExp.$1.length == 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length)
      );
  return fmt;
};

export const formatWeekDate = date => {
  if (date) {
    const arr = [date.substr(0, 4), date.substr(4, 2), date.substr(6)];
    const day = new Date(arr.join('-')).getDay();
    let week;
    switch (day) {
      case 0:
        week = '星期日';
        break;
      case 1:
        week = '星期一';
        break;
      case 2:
        week = '星期二';
        break;
      case 3:
        week = '星期三';
        break;
      case 4:
        week = '星期四';
        break;
      case 5:
        week = '星期五';
        break;
      case 6:
        week = '星期六';
        break;
    }
    return date.substr(4, 2) + '月' + date.substr(6) + '日  ' + week;
  } else {
    return;
  }
};
